<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--部门数据-->
      <el-col :span="4" :xs="24">
        <div class="head-container">
          <el-input
            v-model="deptName"
            placeholder="请输小区名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
        </div>
        <div class="head-container">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            node-key="id"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            :default-checked-keys="['101']"
            ref="tree"
            @node-click="handleNodeClick"
          />
        </div>
      </el-col>
      <!--用户数据-->
      <el-col :span="20" :xs="24">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
            <el-col :span="12">
            <el-form-item label="支付渠道" prop="channel">
              <el-select v-model="form.channel" clearable placeholder="请选择">
                <el-option
                  v-for="item in channelList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公众号名称" prop="tencent">
              <el-input v-model="form.tencent" placeholder="请输入标题" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="主体ID" prop="id">
              <el-input v-model="form.id" placeholder="请输入标题" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商户号" prop="min">
              <el-input v-model="form.min" placeholder="请输入标题" />
            </el-form-item>
          </el-col>
         <el-col :span="24">
            <el-form-item label="主体密钥" prop="themeKey">
              <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入主体密钥" v-model="form.themeKey"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="商户密钥" prop="merchantKey">
              <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入商户密钥" v-model="form.merchantKey"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitForm('form')">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from "axios";
import {
  listUser,
  getUser,
  delUser,
  addUser,
  updateUser,
  resetUserPwd,
  changeUserStatus
} from "@/api/system/user";
import { treeselect } from "@/api/system/dept";
import { listPost } from "@/api/system/post";
import { listRole } from "@/api/system/role";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  components: { Treeselect },
  data() {
    return {
      // 部门树选项
      deptOptions: undefined,
      // 是否显示弹出层
      open: false,
      // 部门名称
      deptName: undefined,
      // 日期范围
      dateRange: [],
      // 状态数据字典
      statusOptions: [],
      // 性别状态字典
      sexOptions: [],
      // 岗位选项
      postOptions: [],
      // 角色选项
      roleOptions: [],
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined
      },
      //表单
      form:{},
      title:'支付设置',
      channelList:[
      {value: '1',label: '微信'},
      {value: '2',label: '支付宝'},
      {value: '3',label: '银联'}
      ],
      rules:{
        channel: [{ required: true, message: "支付渠道不能为空", trigger: "change" }],
        tencent: [{ required: true, message: "公众号名称不能为空", trigger: "blur" }],
        id: [{ required: true, message: "主体ID不能为空", trigger: "blur" }],
        min: [{ required: true, message: "商户号不能为空", trigger: "blur" }],
        themeKey: [{ required: true, message: "主体密钥不能为空", trigger: "blur" }],
        merchantKey: [{ required: true, message: "商户密钥不能为空", trigger: "blur" }],
      },
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getList();
    this.getTreeselect();
    this.getDicts("sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("sys_user_sex").then(response => {
      this.sexOptions = response.data;
    });
    this.getConfigKey("sys.user.initPassword").then(response => {
      this.initPassword = response.data;
    });
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    //    this.$refs.vuetree.setCurrentKey(this.parentId); 
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.getList();
    },
    /** 查询岗位列表 */
    getPosts() {
      listPost().then(response => {
        this.postOptions = response.rows;
      });
    },
    /** 查询角色列表 */
    getRoles() {
      listRole().then(response => {
        this.roleOptions = response.rows;
      });
    },
    //确认更改
    onSubmit(){
        console.log(this.form)
        this.msgSuccess("设置成功");
    },
    //续费确认
    submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            console.log(this.form)
          } else {
            return false;
          }
        });
      },
    //取消
    cancel(){
        this.form = {
            channel:'',
            tencent:'',
            id:'',
            min:'',
            themeKey:'',
            merchantKey:''
        }
        this.resetForm('form')
    }
  }
};
</script>
<style lang="scss" scoped>
/deep/
.sub-btn{
    .el-form-item__content{
        margin-left: 0!important;
    }
}
</style>